package DecisionTree;

import java.util.ArrayList;

import DataModel.Evaluation;
import DataModel.Movie;

public class Entropy {
	
	public static double log2( double a )
	{
		return Math.log(a) / Math.log(2);
	}
	
	
	public static double CalcEntropy(ArrayList<Evaluation> evaluations){
		double entropy=0.0;
		double p;
		for(int i=0;i<=5;i++){
			double same=0;
			for(Evaluation e : evaluations){
				if(Integer.parseInt(e.evaluation)==i) same++;
			}
			if(same!=0) 
			{p=same/evaluations.size();
			entropy+=-p*log2(p);
			}
			
			
		}
		return entropy;
	}
	

	

}
